package com.ktg.mes.qc.controller;

import java.math.BigDecimal;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.ktg.common.core.domain.APIResult;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.poi.*;
import com.ktg.common.utils.poi.tool1.ExcelClass;
import com.ktg.common.utils.poi.tool1.ExcelEnd;
import com.ktg.common.utils.poi.tool1.ExcelEndType;
import com.ktg.common.utils.poi.tool1.ExcelToClass;
import com.ktg.mes.atuoVue.*;
import com.ktg.mes.pro.domain.ProItemNeed;
import com.ktg.mes.unit.sql.domain.MTableColumn;
import com.ktg.mes.unit.sql.domain.SQLDBConfig;
import com.ktg.mes.unit.sql.domain.SQLToolModel;
import com.ktg.mes.unit.sql.service.SQLToolService;
import com.ktg.mes.util.LGLeftJoinQueryWrapper;
import com.ktg.mes.wm.service.IWmStockOutService;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.core.domain.Result;
import com.ktg.mes.qc.domain.QcItemTestingResult;
import com.ktg.mes.qc.service.IQcItemTestingResultService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 产品检测记录Controller
 *
 * @author byteco
 * @date 2023-01-16
 */
@RestController
@RequestMapping("/qc/qcItemTestingResult")
public class QcItemTestingResultController extends BaseController
{
    @Autowired
    private IQcItemTestingResultService qcItemTestingResultService;

    @Autowired
    private IWmStockOutService wmStockOutService;

    @Autowired
    private SQLToolService toolService;

    /**
     * 查询产品检测记录列表
     */
    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:list')")
    @GetMapping("/list")
    public Result<IPage<QcItemTestingResult>> list(QcItemTestingResult qcItemTestingResult,
                                            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                            HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("查询产品检测记录列表",req,null);
        try {
            Page<QcItemTestingResult> page = new Page<QcItemTestingResult>(pageNo, pageSize);
            LGLeftJoinQueryWrapper lgLeftJoinQueryWrapper = new LGLeftJoinQueryWrapper<>(qcItemTestingResult,req.getParameterMap(),pageNo,pageSize);
            IPage<JSONObject> pageList = wmStockOutService.lgPageMapList(lgLeftJoinQueryWrapper);
            return apiLog.ok(pageList);
        }catch (Exception e){
            return apiLog.error(e);
        }
    }



    /**
     * 获取溶解半成品预估 界面配置
     */
    @GetMapping("/selectProductQualitySummarVueSet")
    public AjaxResult selectProductQualitySummarVueSet(String code, HttpServletRequest req){


        WebModel webModel = new WebModel();

        //配置查询条件
        List<QueryParam> queryParamList = new ArrayList<>();
        queryParamList.add(new QueryParam("月份","month", QueryParam.ViewType.DateMonth).setDefaultValue(DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD_HH_MM_SS)));
        queryParamList.add(new QueryParam("","sortCode", QueryParam.ViewType.Hidden).setDefaultValue("selectProductQualitySummarVueSet"));
        webModel.setQueryParams(queryParamList);

        //配置 table 头部标题
        webModel.setColumns(findColumns());

        //查询模块 的按钮
        List<VueButtom> queryParamsButton = new ArrayList<>();

        //导出
        VueButtom vueButtom = new VueButtom("qc:qcItemTestingResult:monthExport","导出", VueButtom.VueButtomType.excelExport)
                .setApiPath("/qc/qcItemTestingResult/monthExport");
        queryParamsButton.add(vueButtom);

        //排序
        VueButtom vueButtom2 = new VueButtom("qc:qcItemTestingResult:list","名称排序", VueButtom.VueButtomType.page)
                .setPagePath("/mes/qc/qcItemTestingResultSort")
                .setFromKeyToKey("queryParams.sortCode","code");
        queryParamsButton.add(vueButtom2);

        webModel.setQueryParamsButton(queryParamsButton);

        //标题
        webModel.setTitle("产品质量总结");

        return AjaxResult.success(webModel);
    }

    /**
     * 获取溶解半成品预估 界面配置
     * @return
     */
    public List<TableColumn> findColumns(){
        List<TableColumn> tableColumnList = new ArrayList<>();
        tableColumnList.add(new TableColumn("型号","specification").setFixed("left"));

        //操作 詳情按鈕
        VueButtom vueButtom = new VueButtom("qc:qcItemTestingResult:list",null, VueButtom.VueButtomType.page)
                .setPagePath("/mes/qc/qcItemTestingResult")
                .setFromKeyToKey("queryParams.month","datePruduct")
                .setFromKeyToKey(".item_name","itemName")
                .setFromKeyToKey(".viscosity","viscosity");
        tableColumnList.add(new TableColumn("产品名称","item_name").setFixed("left").setWidth(100).addVueButtom(vueButtom));

        tableColumnList.add(new TableColumn("粘度","viscosity").setFixed("left"));


        tableColumnList.add(new TableColumn("批次","piChi"));
        tableColumnList.add(new TableColumn("桶数","barrelCount"));
        tableColumnList.add(new TableColumn("外观","appearance"));

        TableColumn ss1 = new TableColumn("研磨粘度(25℃)",null);
        ArrayList<TableColumn> arrayList1 =  new ArrayList<>();
        arrayList1.add(new TableColumn("最小值","minViscosityGrinding"));
        arrayList1.add(new TableColumn("最大值","maxViscosityGrinding"));
        ss1.setSubColumns(arrayList1);
        tableColumnList.add(ss1);

        TableColumn ss2 = new TableColumn("包装前粘度",null);
        ArrayList<TableColumn> arrayList2 =  new ArrayList<>();
        arrayList2.add(new TableColumn("最小值","minViscosityBeforePackagingGrinding"));
        arrayList2.add(new TableColumn("最大值","maxViscosityBeforePackagingGrinding"));
        ss2.setSubColumns(arrayList2);
        tableColumnList.add(ss2);

        TableColumn ss3 = new TableColumn("包装粘度(25℃)",null);
        ArrayList<TableColumn> arrayList3 =  new ArrayList<>();
        arrayList3.add(new TableColumn("最小值","minViscosityPackagingGrinding"));
        arrayList3.add(new TableColumn("最大值","maxViscosityPackagingGrinding"));
        ss3.setSubColumns(arrayList3);
        tableColumnList.add(ss3);

        tableColumnList.add(new TableColumn("共补溶剂(kg)","sumSolventReplenishment"));
        tableColumnList.add(new TableColumn("平均每桶补溶剂数","avgSolventReplenishment"));

        tableColumnList.add(new TableColumn("已入仓数","inCount"));
        tableColumnList.add(new TableColumn("不合格数","unqualifiedCount"));

        TableColumn ss4 = new TableColumn("VT04粘度(25℃)",null);
        ArrayList<TableColumn> arrayList4 =  new ArrayList<>();
        arrayList4.add(new TableColumn("最低值","minViscosity4DayVt06"));
        arrayList4.add(new TableColumn("最高值","maxViscosity4DayVt06"));
        ss4.setSubColumns(arrayList4);
        tableColumnList.add(ss4);

        TableColumn ss5 = new TableColumn("10天VT04粘度",null);
        ArrayList<TableColumn> arrayList5 =  new ArrayList<>();
        arrayList5.add(new TableColumn("最低值","minViscosity10DayVt06"));
        arrayList5.add(new TableColumn("最高值","maxViscosity10DayVt06"));
        ss5.setSubColumns(arrayList5);
        tableColumnList.add(ss5);

        TableColumn ss6 = new TableColumn("4天粘度偏差值",null);
        ArrayList<TableColumn> arrayList6 =  new ArrayList<>();
        arrayList6.add(new TableColumn("最低值","minSubViscosity4DayVt06"));
        arrayList6.add(new TableColumn("最高值","maxSubViscosity4DayVt06"));
        ss6.setSubColumns(arrayList6);
        tableColumnList.add(ss6);

        TableColumn ss7 = new TableColumn("10天粘度偏差值",null);
        ArrayList<TableColumn> arrayList7 =  new ArrayList<>();
        arrayList7.add(new TableColumn("最低值","minSubViscosity10DayVt06"));
        arrayList7.add(new TableColumn("最高值","maxSubViscosity10DayVt06"));
        ss7.setSubColumns(arrayList7);
        tableColumnList.add(ss7);

        TableColumn ss8 = new TableColumn("研磨2(um)",null);
        ArrayList<TableColumn> arrayList8 =  new ArrayList<>();
        arrayList8.add(new TableColumn("细度","maxGrindingFineness1"));
        arrayList8.add(new TableColumn("麻点","maxGrindingPitting1"));
        ss8.setSubColumns(arrayList8);
        tableColumnList.add(ss8);

        TableColumn ss9 = new TableColumn("研磨3(um)",null);
        ArrayList<TableColumn> arrayList9 =  new ArrayList<>();
        arrayList9.add(new TableColumn("细度","maxGrindingFineness2"));
        arrayList9.add(new TableColumn("麻点","maxGrindingPitting2"));
        ss9.setSubColumns(arrayList9);
        tableColumnList.add(ss9);

        TableColumn ss10 = new TableColumn("包装(um)",null);
        ArrayList<TableColumn> arrayList10 =  new ArrayList<>();
        arrayList10.add(new TableColumn("细度","maxPackagingFineness"));
        arrayList10.add(new TableColumn("麻点","maxPackagingPitting"));
        ss10.setSubColumns(arrayList10);
        tableColumnList.add(ss10);

        tableColumnList.add(new TableColumn("硬度（H）","avgHardness"));


        return  tableColumnList;
    }


    /**
     * 查询产品 产品质量总结
     */
    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:monthList')")
    @GetMapping("/monthList")
    public Result<IPage<QcItemTestingResult>> monthList(Date month,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("查询产品 产品质量总结",req,null);
        try {
            if (month == null){
                month = new Date();
            }
            String monthStr = DateUtils.parseDateToStr("YYYY-MM",month);
            List<Map> pageList = qcItemTestingResultService.selectProductQualitySummary(monthStr);

            return apiLog.ok(pageList);
        }catch (Exception e){
            return apiLog.error(e);
        }
    }


    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:monthExport')")
    @Log(title = "导出产品质量总结", businessType = BusinessType.EXPORT)
    @PostMapping("/monthExport")
    public void monthExport(HttpServletResponse response, ProItemNeed proItemNeed, HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("导出客戶产品需求列表",req,proItemNeed);
        try {
            String month = (String) (req.getParameterMap().get("month")[0]);
            Date monthDate = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",month);
            if (monthDate == null){
                monthDate = new Date();
            }
            String monthStr = DateUtils.parseDateToStr("yyyy-MM",monthDate);

            List<Map> mapList = qcItemTestingResultService.selectProductQualitySummary(monthStr);

            //设置第一行标题
            List<ExcelTitle> excelTitleList = new ArrayList<>();

            int colunm = 0;

            ExcelTitle title = new ExcelTitle("产品名称","item_name",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+0,1,0));
            excelTitleList.add(title);

            title = new ExcelTitle("型号","specification",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+1,1,0));
            excelTitleList.add(title);


            title = new ExcelTitle("粘度","viscosity",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+2,1,0));
            excelTitleList.add(title);

            title = new ExcelTitle("批次","piChi",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+3,1,0));
            excelTitleList.add(title);

            title = new ExcelTitle("桶数","barrelCount",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+4,1,0));
            excelTitleList.add(title);


            title = new ExcelTitle("外观","appearance",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+5,1,0));
            excelTitleList.add(title);


            //第二行标题
            Map line2 =  new HashMap();
            ExcelTitle title1 = new ExcelTitle("研磨粘度(25℃)","minViscosityGrinding",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,6,0,1))
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);
            excelTitleList.add(title1);
            excelTitleList.add(new ExcelTitle("研磨粘度(25℃)","maxViscosityGrinding",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("minViscosityGrinding","最小值");
            line2.put("maxViscosityGrinding","最大值");

            ExcelTitle title2 = new ExcelTitle("包装前粘度","minViscosityBeforePackagingGrinding",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,8,0,1))
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);
            excelTitleList.add(title2);
            excelTitleList.add(new ExcelTitle("包装前粘度","maxViscosityBeforePackagingGrinding",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("minViscosityBeforePackagingGrinding","最小值");
            line2.put("maxViscosityBeforePackagingGrinding","最大值");

            title2 = new ExcelTitle("包装粘度(25℃)","minViscosityPackagingGrinding",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,10,0,1))
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);
            excelTitleList.add(title2);
            excelTitleList.add(new ExcelTitle("包装粘度(25℃)","maxViscosityPackagingGrinding",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("minViscosityPackagingGrinding","最小值");
            line2.put("maxViscosityPackagingGrinding","最大值");


            excelTitleList.add(new ExcelTitle("共补溶剂(kg)","sumSolventReplenishment",Float.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+12,1,0)));
            excelTitleList.add(new ExcelTitle("平均每桶补溶剂数","avgSolventReplenishment",Float.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+13,1,0)));
            excelTitleList.add(new ExcelTitle("不合格数","unqualifiedCount",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+14,1,0)));


            title2 = new ExcelTitle("VT04粘度(25℃)","minViscosity4DayVt06",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,15,0,1))
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);
            excelTitleList.add(title2);
            excelTitleList.add(new ExcelTitle("VT04粘度(25℃)","maxViscosity4DayVt06",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("minViscosity4DayVt06","最低值");
            line2.put("maxViscosity4DayVt06","最高值");


            title2 = new ExcelTitle("10天VT04粘度","minViscosity10DayVt06",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,17,0,1))
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);;
            excelTitleList.add(title2);
            excelTitleList.add(new ExcelTitle("10天VT04粘度","maxViscosity10DayVt06",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("minViscosity10DayVt06","最低值");
            line2.put("maxViscosity10DayVt06","最高值");


             title2 = new ExcelTitle("4天粘度偏差值","minSubViscosity4DayVt06",String.class)
                     .addRowStyle( new ExcelCell().setRang(0,19,0,1))
                     .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);
            excelTitleList.add(title2);
            excelTitleList.add(new ExcelTitle("4天粘度偏差值","maxSubViscosity4DayVt06",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("minSubViscosity4DayVt06","最低值");
            line2.put("maxSubViscosity4DayVt06","最高值");


             title2 = new ExcelTitle("10天粘度偏差值","minSubViscosity10DayVt06",String.class)
                     .addRowStyle( new ExcelCell().setRang(0,21,0,1))
                     .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);
            excelTitleList.add(title2);
            excelTitleList.add(new ExcelTitle("10天粘度偏差值","maxSubViscosity10DayVt06",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("minSubViscosity10DayVt06","最低值");
            line2.put("maxSubViscosity10DayVt06","最高值");


             title2 = new ExcelTitle("研磨2(um)","maxGrindingFineness1",String.class)
                     .addRowStyle( new ExcelCell().setRang(0,23,0,1))
                     .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);
            excelTitleList.add(title2);
            excelTitleList.add(new ExcelTitle("研磨2(um)","maxGrindingPitting1",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("maxGrindingFineness1","细度");
            line2.put("maxGrindingPitting1","麻点");

             title2 = new ExcelTitle("研磨3(um)","maxGrindingFineness2",String.class)
                     .addRowStyle( new ExcelCell().setRang(0,25,0,1))
                     .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);
            excelTitleList.add(title2);
            excelTitleList.add(new ExcelTitle("研磨3(um)","maxGrindingPitting2",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("maxGrindingFineness2","细度");
            line2.put("maxGrindingPitting2","麻点");


             title2 = new ExcelTitle("包装(um)","maxPackagingFineness",String.class)
                     .addRowStyle( new ExcelCell().setRang(0,27,0,1))
                     .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE);
            excelTitleList.add(title2);
            excelTitleList.add(new ExcelTitle("包装(um)","maxPackagingPitting",String.class)
                    .addRowColor(1,IndexedColors.GREY_50_PERCENT,IndexedColors.WHITE));
            line2.put("maxPackagingFineness","细度");
            line2.put("maxPackagingPitting","麻点");


            excelTitleList.add(new ExcelTitle("硬度（H）","avgHardness",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+29,1,0)));
            excelTitleList.add(new ExcelTitle("备注","remark",String.class)
                    .addRowStyle( new ExcelCell().setRang(0,colunm+30,1,0)));


            mapList.add(0,line2);



            ExcelRowModel excelRowModel = new ExcelRowModel();

            excelRowModel.setSheetName("产品质量总结");
            excelRowModel.setMapList(mapList);
            excelRowModel.setTitleList(excelTitleList);

            ExcelUtil2 util = new ExcelUtil2();
            util.exportExcel(excelRowModel,response);
            apiLog.ok(null);
        }catch (Exception e){
            apiLog.error(e);
        }
    }


    /**
     * 导出产品检测记录列表
     */
    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:export')")
    @Log(title = "产品检测记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QcItemTestingResult qcItemTestingResult,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("导出产品检测记录列表",req,qcItemTestingResult);
        try {
            List<QcItemTestingResult> list = qcItemTestingResultService.queryList(qcItemTestingResult);
            ExcelUtil<QcItemTestingResult> util = new ExcelUtil<QcItemTestingResult>(QcItemTestingResult.class);
            util.exportExcel(response, list, "产品检测记录数据");
            apiLog.ok(null);
        }catch (Exception e){
            apiLog.error(e);
        }
    }

    /**
     * 获取产品检测记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:query')")
    @GetMapping(value = "/{recordId}")
    public Result<QcItemTestingResult> getInfo(@PathVariable("recordId") Long recordId,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("获取产品检测记录详细信息",req,null);
        try {
            return apiLog.ok(qcItemTestingResultService.getInfo(recordId));
        }catch (Exception e){
            return apiLog.error(e);
        }
    }

    /**
     * 新增产品检测记录
     */
    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:add')")
    @Log(title = "产品检测记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result<String> add(@RequestBody QcItemTestingResult qcItemTestingResult,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("新增产品检测记录",req,qcItemTestingResult);
        QcItemTestingResult  ww = new QcItemTestingResult();
        ww.setItemId(qcItemTestingResult.getItemId());
        List<QcItemTestingResult> list = qcItemTestingResultService.queryList(ww);
        if (list!=null&&list.size()>0){
            return apiLog.fail("添加的产品不能重复！");
        }
        try {
            // 溶剂比例
            if(qcItemTestingResult.getSolventReplenishment()!=null&&qcItemTestingResult.getWeight()!=null){
                float aa = qcItemTestingResult.getSolventReplenishment().floatValue()/qcItemTestingResult.getWeight().floatValue();
                qcItemTestingResult.setDissolutionRatio(BigDecimal.valueOf(aa));
            }
            if (qcItemTestingResult.getViscosity4DayVt06()!=null&&qcItemTestingResult.getTestTemperature1()!=null){
                // 修正粘度(25℃)
                float bb = qcItemTestingResult.getViscosity4DayVt06().floatValue() + (qcItemTestingResult.getTestTemperature1().floatValue() -25)*5;
                qcItemTestingResult.setViscosityCorrected1(BigDecimal.valueOf(bb));
            }
            if (qcItemTestingResult.getViscosity10DayVt06()!=null&&qcItemTestingResult.getTestTemperature2()!=null){
                // 修正粘度(25℃)
                float cc = qcItemTestingResult.getViscosity10DayVt06().floatValue() + (qcItemTestingResult.getTestTemperature2().floatValue() -25)*5;
                qcItemTestingResult.setViscosityCorrected2(BigDecimal.valueOf(cc));
            }

            qcItemTestingResultService.insert(qcItemTestingResult);
            return apiLog.ok("添加成功！");
        }catch (Exception e){
            return apiLog.error(e);
        }
    }


    /**
     * 导入产品检测记录
     */
    @Log(title = "产品检测记录", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<QcItemTestingResult> util = new ExcelUtil<QcItemTestingResult>(QcItemTestingResult.class);
        List<QcItemTestingResult> qcItemTestingResult = util.importExcel(file.getInputStream());
        String message =  qcItemTestingResultService.importTable(qcItemTestingResult,updateSupport);
        return AjaxResult.success(message);
//        String operName = getUsername();
//        String message = userService.importUser(userList, updateSupport, operName);
//        return AjaxResult.success(message);
    }


    /**
     * 导入产品检测记录
     */
    @Log(title = "产品检测记录", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:import')")
    @PostMapping("/importData2")
    public AjaxResult importData2(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelClass util = new ExcelClass();
        List<ExcelToClass> list = new ArrayList<>();
        int start = 0;

        list.add(new ExcelToClass(start+0,"产品名称","itemName",String.class));
        list.add(new ExcelToClass(start+1,"型号","specification",String.class));
        list.add(new ExcelToClass(start+2,"粘度","viscosity",String.class));
        list.add(new ExcelToClass(start+3,"生产日期","datePruduct",Date.class));
        list.add(new ExcelToClass(start+4,"批号","batchNo",String.class));

        list.add(new ExcelToClass(start+5,"桶号","barrelNo",String.class));
        list.add(new ExcelToClass(start+6,"外观","appearance",String.class));
        list.add(new ExcelToClass(start+7,"重量","weight",Double.TYPE));
        list.add(new ExcelToClass(start+8,"实际重量","weightReal",Double.TYPE));
        list.add(new ExcelToClass(start+9,"溶剂比例","dissolutionRatio",Double.TYPE));
        list.add(new ExcelToClass(start+10,"研磨粘度(25℃)","viscosityGrinding",Integer.TYPE));

        list.add(new ExcelToClass(start+11,"包装前粘度(25℃)","viscosityBeforePackaging",Integer.TYPE));
        list.add(new ExcelToClass(start+12,"补溶剂(Kg)","solventReplenishment",Integer.class));
        list.add(new ExcelToClass(start+13,"包装粘度(25℃)","viscosityPackaging",Integer.class));
        list.add(new ExcelToClass(start+14,"包装时间","datePackaging",Date.class));
        list.add(new ExcelToClass(start+15,"品质判定","qualityJudgment",String.class));

        list.add(new ExcelToClass(start+16,"测试温度","testTemperature1",Integer.TYPE));
        list.add(new ExcelToClass(start+17,"4天VT06粘度","viscosity4DayVt06",Integer.TYPE));
        list.add(new ExcelToClass(start+18,"修正粘度(25℃)","viscosityCorrected1",Integer.TYPE));

        list.add(new ExcelToClass(start+19,"测试温度","testTemperature2",Integer.TYPE));
        list.add(new ExcelToClass(start+20,"10天VT06粘度","viscosity10DayVt06",Integer.TYPE));
        list.add(new ExcelToClass(start+21,"修正粘度(25℃)","viscosityCorrected2",Integer.TYPE));

        list.add(new ExcelToClass(start+22,"grindingFineness1",Double.TYPE));
        list.add(new ExcelToClass(start+23,"grindingPitting1",Double.TYPE));

        list.add(new ExcelToClass(start+24,"grindingFineness2",Double.TYPE));
        list.add(new ExcelToClass(start+25,"grindingPitting2",Double.TYPE));

        list.add(new ExcelToClass(start+26,"packagingFineness",Double.TYPE));
        list.add(new ExcelToClass(start+27,"packagingPitting",Double.TYPE));

        list.add(new ExcelToClass(start+28,"hardness",Integer.TYPE));


        List<Map> mapList = util.importExcel(file.getInputStream(),list,5,1,new ExcelEnd(ExcelEndType.cellGroupAllNull,"itemName,specification,viscosity,datePruduct,batchNo"));

        Map<String, MTableColumn> sss = toolService.getColumType(SQLDBConfig.master,"qc_item_testing_result");

        for (int i = 0;i < mapList.size();i++){
            SQLToolModel sqlToolModel = new SQLToolModel(SQLDBConfig.master,"qc_item_testing_result",sss);
            Map map = mapList.get(i);
            Set<String> keys = map.keySet();
            for (String key:keys) {
                sqlToolModel.insertColumAndValue(sqlToolModel.camelToUnderline(key),map.get(key));
            }
            toolService.insertModel(sqlToolModel);
        }


        return AjaxResult.success("message");
    }


    /**
     * 修改产品检测记录
     */
    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:edit')")
    @Log(title = "产品检测记录", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public Result<String> edit(@RequestBody QcItemTestingResult qcItemTestingResult,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("修改产品检测记录",req,qcItemTestingResult);
        try {
            qcItemTestingResultService.update(qcItemTestingResult);
            return apiLog.ok("编辑成功！");
        }catch (Exception e){
            return apiLog.error(e);
        }
    }

    /**
     * 删除产品检测记录
     */
    @PreAuthorize("@ss.hasPermi('qc:qcItemTestingResult:remove')")
    @Log(title = "产品检测记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public Result<String> remove(@PathVariable Long[] recordIds,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("删除产品检测记录",req,null);
        try {
            qcItemTestingResultService.delete(recordIds);
            return apiLog.ok("删除成功！");
        }catch (Exception e){
            return apiLog.error(e);
        }

    }
}
